package com.kh.pajx.sop.util.security.userdetails;

import com.kh.pajx.sop.util.security.exception.AccountExpiredException;
import com.kh.pajx.sop.util.security.exception.AccountStatusException;
import com.kh.pajx.sop.util.security.exception.CredentialsExpiredException;
import com.kh.pajx.sop.util.security.exception.DisabledException;
import com.kh.pajx.sop.util.security.exception.LockedException;


public class AccountStatusUserDetailsChecker implements UserDetailsChecker{

	@Override
	public void check(UserDetails user) throws AccountStatusException {
		
		if (!user.isAccountNonLocked()) {
			throw new LockedException();
		}

		if (!user.isEnabled()) {
			throw new DisabledException("User is disabled", user);
		}

		if (!user.isAccountNonExpired()) {
			throw new AccountExpiredException("User account has expired", user);
		}

		if (!user.isCredentialsNonExpired()) {
			throw new CredentialsExpiredException(
					"User credentials have expired", user);
		}
	}
}
